package com.atguigu.lease.web.admin.schedule;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.object.UpdatableSqlQuery;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author 张智勇
 * @date 2025年08月20日 17:02
 */

//@Component
public class ScheduledTasks {

    @Autowired
    LeaseAgreementService leaseAgreementService;


    @Scheduled(cron = "1/10 * * * * ?")
    public void checkLeaseStatus(){
        System.out.println("==============我是定时器============");
        UpdateWrapper<LeaseAgreement> leaseAgreementUpdateWrapper = new UpdateWrapper<>();
        leaseAgreementUpdateWrapper.le("lease_end_date",new Date());
        leaseAgreementUpdateWrapper. notIn("status",2,5,7);  //这里为什么是2,5,7 ？？
        leaseAgreementUpdateWrapper.set("status", LeaseStatus.EXPIRED);
        leaseAgreementService.update(leaseAgreementUpdateWrapper);
    }
}
